package com.diy.common.bussiness.service.defaultService;


import com.alibaba.fastjson.JSON;
import com.diy.common.baseModel.BaseDiyBean;
import com.diy.common.baseModel.BaseDiyQueryParamsBean;

/**
 * Created by Honglei.Yang on 2015/11/19.
 */
public class DefaultSaveable<T extends BaseDiyBean,P extends BaseDiyQueryParamsBean> {

    //默认修改
    private Savable<T, P> defaultChangeServiceImpl;
    //默认创建
    private Savable<T, P> defaultCreateServiceImpl;
    //默认删除
    private Savable<T, P> defaultDeleteServiceImpl;
    //默认单条查询
    private Savable<T, P> defaultSelectServiceImpl;

    protected DefaultSaveable(Savable<T, P> defaultChangeServiceImpl,
                           Savable<T, P> defaultCreateServiceImpl,
                           Savable<T, P> defaultDeleteServiceImpl,
                           Savable<T, P> defaultSelectServiceImpl) {
        this.defaultChangeServiceImpl = defaultChangeServiceImpl;
        this.defaultCreateServiceImpl = defaultCreateServiceImpl;
        this.defaultDeleteServiceImpl = defaultDeleteServiceImpl;
        this.defaultSelectServiceImpl = defaultSelectServiceImpl;
    }

    //默认创建
    public T create(P arg) {
      return   defaultCreateServiceImpl.save(arg);
    }

    //默认删除
    public T delete(P arg) {
       return defaultDeleteServiceImpl.save(arg);
    }

    //默认修改
    public T change(P arg) {
       return defaultChangeServiceImpl.save(arg);
    }

    //默认单条查询
    public T select(P arg) {
        System.out.println("trigger service select method"+ JSON.toJSONString(arg));
        return defaultSelectServiceImpl.save(arg);
    }
}